//
//  MeatSearchItemView.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/1.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatSearchItemView.h"

#define mGap 8.f
#define mItem (KScreenWidth - 30 - 4*mGap)/3.0


@implementation MeatSearchItemView

#pragma mark - lifecycle methods

- (void)setupUI{
    
    [self addSubview:self.shopIcon];
    [self addSubview:self.salesIcon];
    [self addSubview:self.priceLab];
    [_shopIcon addSubview:self.nameLab];
}


- (void)setupLayout{
    
    
    self.width = mItem;
    self.height = mItem + 42;
    
    {
        _shopIcon.size = CGSizeMake(mItem, mItem);
        _shopIcon.mj_x = _shopIcon.mj_y = 0;
    }
    
    {
        _salesIcon.size = CGSizeMake(36, 17);
        _salesIcon.mj_x = _salesIcon.mj_y = 0;
    }
    
    {
        _nameLab.size = CGSizeMake(50, 21);
        _nameLab.mj_x = 0;
        _nameLab.mj_y = _shopIcon.bottom - 21;
    }
    
    {
        _priceLab.size = CGSizeMake(mItem, 17);
        _priceLab.mj_y = _shopIcon.bottom + 10;
        _priceLab.mj_x = 0;
    }
    
    
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    
    CGFloat h = mItem/2.0;
    CGFloat w = 15;
    UIBezierPath *path1 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, h, h) byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(w, w)];
    UIBezierPath *path2 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(h, 0, h, h) byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(w, w)];
    UIBezierPath *path3 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, h, h, h) byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(3, 3)];
    UIBezierPath *path4 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(h, h, h, h) byRoundingCorners:UIRectCornerBottomRight cornerRadii:CGSizeMake(w, w)];

    [path1 appendPath:path2];
    [path1 appendPath:path3];
    [path1 appendPath:path4];
    
    maskLayer.path = path1.CGPath;
    _shopIcon.layer.mask = maskLayer;

}


#pragma mark - setter methods


#pragma mark - getter methods

- (UIImageView *)shopIcon{
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
        _shopIcon.image = [UIImage imageNamed:@"p1"];
    }
    return _shopIcon;
}


- (UILabel *)priceLab{
    
    if (!_priceLab) {
        _priceLab = [UILabel makeLabelWithText:@"¥ 172.8" textColor:UIColorFromRGB(0xF25C62) font:mMediumFont(12) textAliment:1];
    }
    return _priceLab;
}

- (UILabel *)nameLab{
    
    if (!_nameLab) {
        _nameLab = [UILabel makeLabelWithText:@"五花肉" textColor:UIColorFromRGB(0xE5E5E5) font:mMediumFont(12) textAliment:1];
        _nameLab.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5f];
    }
    return _nameLab;
}


- (UIImageView *)salesIcon{
    
    if (!_salesIcon) {
        _salesIcon = [UIImageView makeImageByImageName:@"meat_shop_sales" cornerRadius:0];
        
    }
    return _salesIcon;
}



@end
